package com.yongqi.duocai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yongqi.duocai.entity.ShoppingCart;
import com.yongqi.duocai.entity.result.ChooseShoppingInfoResult;
import com.yongqi.duocai.entity.result.ShoppingCarResult;
import com.yongqi.duocai.mapper.ShoppingCartMapper;
import com.yongqi.duocai.service.ShoppingCartService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 夏亮辉
 * @since 2021-06-19
 */
@Service
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {

    @Autowired
    private ShoppingCartMapper shoppingCartMapper;

    @Override
    public List<ShoppingCarResult> queryInfo(Integer id) {
        return shoppingCartMapper.selectAllByUseId(id);
    }

    /**
     * 根据 id 查询 选中的商品信息
     *
     * @param ids
     * @return
     */
    @Override
    public List<ChooseShoppingInfoResult> queryChoose(Integer[] ids) {
        return shoppingCartMapper.selectChoseById(ids);
    }

    @Override
    public List<ChooseShoppingInfoResult> queryGoods(Integer userId, Integer[] ids) {
        return shoppingCartMapper.selectGoods(userId, ids);
    }

    /**
     * 按条件查询
     * @param shoppingCart
     * @return
     */
    @Override
    public ShoppingCart queryOneByCondition(Integer userId, ShoppingCart shoppingCart) {
        QueryWrapper<ShoppingCart> queryWrapper = new QueryWrapper();
        queryWrapper.eq("goods_id", shoppingCart.getGoodsId())
                    .eq("user_id", userId);
        return shoppingCartMapper.selectOne(queryWrapper);
    }
}
